package com.iou.bean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.j256.ormlite.dao.ForeignCollection;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.field.ForeignCollectionField;
import com.j256.ormlite.table.DatabaseTable;

/**
 * User class. ORM between the program and the DB is done using ORMLite.
 * 
 */
@DatabaseTable(tableName = "users")
public class IOUUser implements Serializable {
    @DatabaseField(id = true)
    private String username;
    @DatabaseField
    private String password;
    @ForeignCollectionField
    private ForeignCollection<IOUNote> notes;

    /**
     * Default constructor.
     */
    public IOUUser() {
    }

    /**
     * Constructor.
     * 
     * @param username
     * @param password
     */
    public IOUUser(String username, String password) {
        this.username = username;
        this.password = password;
    }

    /**
     * 
     * @param username
     */
    public void setUsername(String username) {
        this.username = username;
    }

    /**
     * 
     * @param password
     */
    public void setPassword(String password) {
        this.password = password;
    }

    /**
     * 
     * @return
     */
    public String getUsername() {
        return this.username;
    }

    /**
     * 
     * @return
     */
    public String getPassword() {
        return this.password;
    }

    /**
     * 
     * @return
     */
    public List<IOUNote> getNotes() {
        ArrayList<IOUNote> noteList = new ArrayList<IOUNote>();
        for (IOUNote item : notes) {
            noteList.add(item);
        }
        return noteList;
    }

    /**
     * 
     * @param notes
     */
    public void setNotes(ForeignCollection<IOUNote> notes) {
        this.notes = notes;
    }

    @Override
    public String toString() {
        // return getId() + " | " + getUsername() + " | " + getPassword();
        return getUsername() + " | " + getPassword();

    }
}
